package com.luhuiguo.sso.entity;

import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import com.luhuiguo.sso.entity.AuditableEntity;

@Entity
@Table(name = "t_activity")
public class Activity extends AuditableEntity {

	private static final long serialVersionUID = -4768408149413023322L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	@ManyToOne
	private User user;

	@ManyToOne
	private Site site;

	@Enumerated
	private AuthAction action;

	public Activity() {
		super();
	}

	public Activity(User user, Site site, AuthAction action) {
		super();
		this.user = user;
		this.site = site;
		this.action = action;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Site getSite() {
		return site;
	}

	public void setSite(Site site) {
		this.site = site;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	/**
	 * @return the action
	 */
	public AuthAction getAction() {
		return action;
	}

	/**
	 * @param action
	 *            the action to set
	 */
	public void setAction(AuthAction action) {
		this.action = action;
	}

	@Override
	public boolean equals(Object other) {
		if (!(other instanceof Approval)) {
			return false;
		}
		Approval castOther = (Approval) other;
		return new EqualsBuilder().append(this.getId(), castOther.getId())
				.isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(getId()).toHashCode();
	}

	@Override
	public String toString() {
		ToStringBuilder sb = new ToStringBuilder(this,
				ToStringStyle.SIMPLE_STYLE).append("site", this.site).append(
				"user", this.user).append("action", this.action);
		return sb.toString();
	}

}
